package com.shortLinked.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shortLinked.admin.common.convention.result.Result;
import com.shortLinked.admin.common.convention.result.Results;
import com.shortLinked.admin.remote.ShortLinkActualRemoteService;
import com.shortLinked.admin.remote.dto.req.RecoverRecycleBinReqDTO;
import com.shortLinked.admin.remote.dto.req.RecycleBinReqDTO;
import com.shortLinked.admin.remote.dto.req.RemoveRecycleBinReqDTO;
import com.shortLinked.admin.remote.dto.req.ShortLinkRecycleBinPageReqDTO;
import com.shortLinked.admin.remote.dto.resp.ShortLinkPageRespDTO;
import com.shortLinked.admin.service.RecycleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短链接回收站控制层
 */
@RestController(value = "recycleBinControllerByAdmin")
@RequiredArgsConstructor
public class RecycleBinController {

    private final RecycleService recycleService;

    private final ShortLinkActualRemoteService shortLinkActualRemoteService;

    /**
     * 短链接回收站保存功能
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinReqDTO requestParam) {
        shortLinkActualRemoteService.saveRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 回收站短链接分页查询 - 当前用户
     */
    @GetMapping("/api/short-link/admin/v1/recycle-bin/page")
    public Result<Page<ShortLinkPageRespDTO>> pageRecycleBinShortLink(ShortLinkRecycleBinPageReqDTO requestParam) {
        return recycleService.pageRecycleBinShortLink(requestParam);
    }

    /**
     * 回收站短链接恢复功能
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/recover")
    public Result<Void> recoverRecycleBin(@RequestBody RecoverRecycleBinReqDTO requestParam) {
        shortLinkActualRemoteService.recoverRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 回收站短链接移除功能
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/remove")
    public Result<Void> recoverRecycleBin(@RequestBody RemoveRecycleBinReqDTO requestParam) {
        shortLinkActualRemoteService.removeRecycleBin(requestParam);
        return Results.success();
    }
}